import { Controller } from "egg";
// import { DepartmentProps } from "../model/Department";

export default class DepartmentController extends Controller {
  public async index() {
    const { ctx } = this;
    const res = await ctx.service.department.findList();
    ctx.helper.success({ ctx, res });
  }

  public async create() {
    const { ctx, service } = this;
    const { department_name } = ctx.request.body;
    const data = await service.department.findByName(department_name);
    if (data) {
      return ctx.helper.error({ ctx, errorType: "commonAlreadyExists" });
    }
    const res = await service.department.add(ctx.request.body);
    ctx.helper.success({ ctx, res });
  }
}
